package com.yang.api;

import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.serverct.ersha.api.AttributeAPI;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class AttributePlustApi {
    public static void apigui(Player player) throws IOException {
        File file0 = new File(plugin.getDataFolder(), "playerap");
        if (!file0.exists()) {
            file0.mkdirs();
        }
        File file = new File(file0, player.getName() + ".yml");
        YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
        ConfigurationSection ap = yml.getConfigurationSection("ap");
        if (!file.exists()) {
            file.createNewFile();
            yml.set("ap.雷击几率", 0);
            yml.set("ap.闪避几率", 0);
            yml.set("ap.真实伤害", 0);
            yml.set("ap.反弹几率", 0);
            yml.set("ap.冰冻几率", 0);
            yml.set("ap.箭伤免疫率", 0);
            yml.set("ap.护甲值", 0);
            yml.set("ap.暴击几率", 0);
            yml.set("ap.物理防御", 0);
            yml.set("ap.物理伤害", 0);
            yml.set("ap.吸血几率", 0);
            yml.set("ap.测试脚本属性", 0);
            yml.set("ap.燃烧几率", 0);
            yml.set("ap.盾牌格挡率", 0);
            yml.set("ap.PVP伤害", 0);
            yml.set("ap.召唤强度", 0);
            yml.set("ap.吸血抵抗", 0);
            yml.set("ap.雷击伤害", 0);
            yml.set("ap.箭矢穿透率", 0);
            yml.set("ap.吸血闪避", 0);
            yml.set("ap.命中几率", 0);
            yml.set("ap.暴击抵抗", 0);
            yml.set("ap.护甲穿透", 0);
            yml.set("ap.PVP防御", 0);
            yml.set("ap.冰冻强度", 0);
            yml.set("ap.吸血倍率", 0);
            yml.set("ap.箭术精准", 0);
            yml.set("ap.破盾几率", 0);
            yml.set("ap.蓄力加成", 0);
            yml.set("ap.生命恢复", 0);
            yml.set("ap.破甲几率", 0);
            yml.set("ap.反弹倍率", 0);
            yml.set("ap.暴伤倍率", 0);
            yml.set("ap.经验加成", 0);
            yml.set("ap.暴击闪避", 0);
            yml.set("ap.PVE防御", 0);
            yml.set("ap.蓄力干扰", 0);
            yml.set("ap.燃烧伤害", 0);
            yml.set("ap.暴伤抵抗", 0);
            yml.set("ap.PVE伤害", 0);
            yml.set("ap.箭矢速度", 0);
            yml.set("ap.百分比恢复", 0);
            yml.set("ap.生命力", 0);
            yml.set("ap.移速加成", 0);
            yml.save(file);
            HashMap<String, Integer> map = new HashMap<>();
            map.put("雷击几率", 0);
            map.put("闪避几率", 0);
            map.put("真实伤害", 0);
            map.put("反弹几率", 0);
            map.put("冰冻几率", 0);
            map.put("箭伤免疫率", 0);
            map.put("护甲值", 0);
            map.put("暴击几率", 0);
            map.put("物理防御", 0);
            map.put("物理伤害", 0);
            map.put("吸血几率", 0);
            map.put("测试脚本属性", 0);
            map.put("燃烧几率", 0);
            map.put("盾牌格挡率", 0);
            map.put("PVP伤害", 0);
            map.put("召唤强度", 0);
            map.put("吸血抵抗", 0);
            map.put("雷击伤害", 0);
            map.put("箭矢穿透率", 0);
            map.put("吸血闪避", 0);
            map.put("命中几率", 0);
            map.put("暴击抵抗", 0);
            map.put("护甲穿透", 0);
            map.put("PVP防御", 0);
            map.put("冰冻强度", 0);
            map.put("吸血倍率", 0);
            map.put("箭术精准", 0);
            map.put("破盾几率", 0);
            map.put("蓄力加成", 0);
            map.put("生命恢复", 0);
            map.put("破甲几率", 0);
            map.put("反弹倍率", 0);
            map.put("暴伤倍率", 0);
            map.put("经验加成", 0);
            map.put("暴击闪避", 0);
            map.put("PVE防御", 0);
            map.put("蓄力干扰", 0);
            map.put("燃烧伤害", 0);
            map.put("暴伤抵抗", 0);
            map.put("PVE伤害", 0);
            map.put("箭矢速度", 0);
            map.put("百分比恢复", 0);
            map.put("生命力", 0);
            map.put("移速加成", 0);
            plugin.apmap.put(player.getName(), map);
        } else {
            HashMap<String, Integer> map = new HashMap<>();
            map.put("雷击几率", yml.getInt("ap.雷击几率"));
            map.put("闪避几率", yml.getInt("ap.闪避几率"));
            map.put("真实伤害", yml.getInt("ap.真实伤害"));
            map.put("反弹几率", yml.getInt("ap.反弹几率"));
            map.put("冰冻几率", yml.getInt("ap.冰冻几率"));
            map.put("箭伤免疫率", yml.getInt("ap.箭伤免疫率"));
            map.put("护甲值", yml.getInt("ap.护甲值"));
            map.put("暴击几率", yml.getInt("ap.暴击几率"));
            map.put("物理防御", yml.getInt("ap.物理防御"));
            map.put("物理伤害", yml.getInt("ap.物理伤害"));
            map.put("吸血几率", yml.getInt("ap.吸血几率"));
            map.put("测试脚本属性", yml.getInt("ap.测试脚本属性"));
            map.put("燃烧几率", yml.getInt("ap.燃烧几率"));
            map.put("盾牌格挡率", yml.getInt("ap.盾牌格挡率"));
            map.put("PVP伤害", yml.getInt("ap.PVP伤害"));
            map.put("召唤强度", yml.getInt("ap.召唤强度"));
            map.put("吸血抵抗", yml.getInt("ap.吸血抵抗"));
            map.put("雷击伤害", yml.getInt("ap.雷击伤害"));
            map.put("箭矢穿透率", yml.getInt("ap.箭矢穿透率"));
            map.put("吸血闪避", yml.getInt("ap.吸血闪避"));
            map.put("命中几率", yml.getInt("ap.命中几率"));
            map.put("暴击抵抗", yml.getInt("ap.暴击抵抗"));
            map.put("护甲穿透", yml.getInt("ap.护甲穿透"));
            map.put("PVP防御", yml.getInt("ap.PVP防御"));
            map.put("冰冻强度", yml.getInt("ap.冰冻强度"));
            map.put("吸血倍率", yml.getInt("ap.吸血倍率"));
            map.put("箭术精准", yml.getInt("ap.箭术精准"));
            map.put("破盾几率", yml.getInt("ap.破盾几率"));
            map.put("蓄力加成", yml.getInt("ap.蓄力加成"));
            map.put("生命恢复", yml.getInt("ap.生命恢复"));
            map.put("破甲几率", yml.getInt("ap.破甲几率"));
            map.put("反弹倍率", yml.getInt("ap.反弹倍率"));
            map.put("暴伤倍率", yml.getInt("ap.暴伤倍率"));
            map.put("经验加成", yml.getInt("ap.经验加成"));
            map.put("暴击闪避", yml.getInt("ap.暴击闪避"));
            map.put("PVE防御", yml.getInt("ap.PVE防御"));
            map.put("蓄力干扰", yml.getInt("ap.蓄力干扰"));
            map.put("燃烧伤害", yml.getInt("ap.燃烧伤害"));
            map.put("暴伤抵抗", yml.getInt("ap.暴伤抵抗"));
            map.put("PVE伤害", yml.getInt("ap.PVE伤害"));
            map.put("箭矢速度", yml.getInt("ap.箭矢速度"));
            map.put("百分比恢复", yml.getInt("ap.百分比恢复"));
            map.put("生命力", yml.getInt("ap.生命力"));
            map.put("移速加成", yml.getInt("ap.移速加成"));
            plugin.apmap.put(player.getName(), map);
        }
        playerapload();
    }

    public static void playerapload() {
        for (Player player : Bukkit.getOnlinePlayers()) {
            HashMap<String, Integer> map = plugin.apmap.get(player.getName());
            List<String> list = new ArrayList<>();
            for (String apname : map.keySet()) {
                String ls = String.valueOf(map.get(apname));
                switch (apname) {
                    case "雷击几率":
                    case "闪避几率":
                    case "反弹几率":
                    case "冰冻几率":
                    case "箭伤免疫率":
                    case "暴击几率":
                    case "吸血几率":
                    case "燃烧几率":
                    case "盾牌格挡率":
                    case "箭矢穿透率":
                    case "吸血闪避":
                    case "命中几率":
                    case "暴击抵抗":
                    case "护甲穿透":
                    case "吸血倍率":
                    case "破盾几率":
                    case "蓄力加成":
                    case "破甲几率":
                    case "反弹倍率":
                    case "暴伤倍率":
                    case "暴击闪避":
                    case "蓄力干扰":
                    case "箭矢速度":
                    case "百分比恢复":
                    case "移速加成":
                        ls = ls + "%";
                        break;
                    default:
                        break;
                }
                list.add(apname + ":" + ls);
            }
            AttributeAPI.addSourceAttribute(AttributeAPI.getAttrData(player), String.valueOf(plugin.getClass()), list);
        }
    }

    public static void playerupapload(Player player) throws IOException {
        File file0 = new File(plugin.getDataFolder(), "playerap");
        if (!file0.exists()) {
            file0.mkdirs();
        }
        File file = new File(file0, player.getName() + ".yml");
        YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
        ConfigurationSection ap = yml.getConfigurationSection("ap");
        HashMap<String, Integer> map = new HashMap<>();
        map.put("雷击几率", yml.getInt("ap.雷击几率"));
        map.put("闪避几率", yml.getInt("ap.闪避几率"));
        map.put("真实伤害", yml.getInt("ap.真实伤害"));
        map.put("反弹几率", yml.getInt("ap.反弹几率"));
        map.put("冰冻几率", yml.getInt("ap.冰冻几率"));
        map.put("箭伤免疫率", yml.getInt("ap.箭伤免疫率"));
        map.put("护甲值", yml.getInt("ap.护甲值"));
        map.put("暴击几率", yml.getInt("ap.暴击几率"));
        map.put("物理防御", yml.getInt("ap.物理防御"));
        map.put("物理伤害", yml.getInt("ap.物理伤害"));
        map.put("吸血几率", yml.getInt("ap.吸血几率"));
        map.put("测试脚本属性", yml.getInt("ap.测试脚本属性"));
        map.put("燃烧几率", yml.getInt("ap.燃烧几率"));
        map.put("盾牌格挡率", yml.getInt("ap.盾牌格挡率"));
        map.put("PVP伤害", yml.getInt("ap.PVP伤害"));
        map.put("召唤强度", yml.getInt("ap.召唤强度"));
        map.put("吸血抵抗", yml.getInt("ap.吸血抵抗"));
        map.put("雷击伤害", yml.getInt("ap.雷击伤害"));
        map.put("箭矢穿透率", yml.getInt("ap.箭矢穿透率"));
        map.put("吸血闪避", yml.getInt("ap.吸血闪避"));
        map.put("命中几率", yml.getInt("ap.命中几率"));
        map.put("暴击抵抗", yml.getInt("ap.暴击抵抗"));
        map.put("护甲穿透", yml.getInt("ap.护甲穿透"));
        map.put("PVP防御", yml.getInt("ap.PVP防御"));
        map.put("冰冻强度", yml.getInt("ap.冰冻强度"));
        map.put("吸血倍率", yml.getInt("ap.吸血倍率"));
        map.put("箭术精准", yml.getInt("ap.箭术精准"));
        map.put("破盾几率", yml.getInt("ap.破盾几率"));
        map.put("蓄力加成", yml.getInt("ap.蓄力加成"));
        map.put("生命恢复", yml.getInt("ap.生命恢复"));
        map.put("破甲几率", yml.getInt("ap.破甲几率"));
        map.put("反弹倍率", yml.getInt("ap.反弹倍率"));
        map.put("暴伤倍率", yml.getInt("ap.暴伤倍率"));
        map.put("经验加成", yml.getInt("ap.经验加成"));
        map.put("暴击闪避", yml.getInt("ap.暴击闪避"));
        map.put("PVE防御", yml.getInt("ap.PVE防御"));
        map.put("蓄力干扰", yml.getInt("ap.蓄力干扰"));
        map.put("燃烧伤害", yml.getInt("ap.燃烧伤害"));
        map.put("暴伤抵抗", yml.getInt("ap.暴伤抵抗"));
        map.put("PVE伤害", yml.getInt("ap.PVE伤害"));
        map.put("箭矢速度", yml.getInt("ap.箭矢速度"));
        map.put("百分比恢复", yml.getInt("ap.百分比恢复"));
        map.put("生命力", yml.getInt("ap.生命力"));
        map.put("移速加成", yml.getInt("ap.移速加成"));
        plugin.apmap.put(player.getName(), map);
        AttributeAPI.getAttrData(player).clearApiAttribute();
        HashMap<String, Integer> map1 = plugin.apmap.get(player.getName());
        List<String> list = new ArrayList<>();
        for (String apname : map1.keySet()) {
            String ls = String.valueOf(map1.get(apname));
            switch (apname) {
                case "雷击几率":
                case "闪避几率":
                case "反弹几率":
                case "冰冻几率":
                case "箭伤免疫率":
                case "暴击几率":
                case "吸血几率":
                case "燃烧几率":
                case "盾牌格挡率":
                case "箭矢穿透率":
                case "吸血闪避":
                case "命中几率":
                case "暴击抵抗":
                case "护甲穿透":
                case "吸血倍率":
                case "破盾几率":
                case "蓄力加成":
                case "破甲几率":
                case "反弹倍率":
                case "暴伤倍率":
                case "暴击闪避":
                case "蓄力干扰":
                case "箭矢速度":
                case "百分比恢复":
                case "移速加成":
                    ls = ls + "%";
                    break;
                default:
                    break;
            }
            list.add(apname + ":" + ls);
        }
        AttributeAPI.addSourceAttribute(AttributeAPI.getAttrData(player), String.valueOf(plugin.getClass()), list);
        apapi.chenghaoapadd(player, plugin.playernowchenghao.get(player.getName()));
    }

    public static void chenghaoapadd(Player player, String itemname) {
        ConfigurationSection csf = plugin.getConfig().getConfigurationSection("apchenghao");
        for (String ch : csf.getKeys(false)) {
            //player.sendMessage(ch+","+itemname);
            if (ch.equals(itemname)) {
                List<String> lorelist = new ArrayList<>();
                for (String name : plugin.getConfig().getStringList("apchenghao." + itemname)) {
                    lorelist.add(name);
                }
                AttributeAPI.getAttrData(player).clearApiAttribute();
                HashMap<String, Integer> map1 = plugin.apmap.get(player.getName());
                if (map1 != null) {
                    List<String> list = new ArrayList<>();
                    for (String apname : map1.keySet()) {
                        String ls = String.valueOf(map1.get(apname));
                        switch (apname) {
                            case "雷击几率":
                            case "闪避几率":
                            case "反弹几率":
                            case "冰冻几率":
                            case "箭伤免疫率":
                            case "暴击几率":
                            case "吸血几率":
                            case "燃烧几率":
                            case "盾牌格挡率":
                            case "箭矢穿透率":
                            case "吸血闪避":
                            case "命中几率":
                            case "暴击抵抗":
                            case "护甲穿透":
                            case "吸血倍率":
                            case "破盾几率":
                            case "蓄力加成":
                            case "破甲几率":
                            case "反弹倍率":
                            case "暴伤倍率":
                            case "暴击闪避":
                            case "蓄力干扰":
                            case "箭矢速度":
                            case "百分比恢复":
                            case "移速加成":
                                ls = ls + "%";
                                break;
                            default:
                                break;
                        }
                        list.add(apname + ":" + ls);
                    }
                    AttributeAPI.addSourceAttribute(AttributeAPI.getAttrData(player), String.valueOf(plugin.getClass()), list);
                }
                AttributeAPI.addSourceAttribute(AttributeAPI.getAttrData(player), String.valueOf(plugin.getClass()), lorelist);
            }
        }
    }
}
